import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    baseUrl: "https://shslqxh.1meeting.com/coach/", // 默认前端地址
    baseAPIUrl: "https://shslqxh.1meeting.com/coach/api", // 默认后端地址
    // baseUrl: "https://shslqxh.1meeting.com/testcoach/", // 默认前端地址
    // baseAPIUrl: "https://shslqxh.1meeting.com/testcoach/api", // 默认后端地址
    // 基本信息
    loginToken: JSON.parse(sessionStorage.getItem("COACH_LOGIN_TOKEN")) || "", // 登录验证token
    loginUserId: JSON.parse(sessionStorage.getItem("COACH_LOGIN_USERID")) || "", // 登录用户id
    hasPhone: JSON.parse(sessionStorage.getItem("COACH_HAS_PHONE")) || false, // 登录用户是否绑定手机
    isRegister:
      JSON.parse(sessionStorage.getItem("COACH_IS_REGISTER")), // 登录用户是否完善信息
    isRefereePay:
      JSON.parse(sessionStorage.getItem("COACH_IS_REFEREEPAY")) || false, // 登录用户是否存在已支付裁判员注册订单
    isAnswer: JSON.parse(sessionStorage.getItem("COACH_IS_ANSWER")) || false, // 登录用户是否完成裁判员上岗答题
    before_Path: JSON.parse(sessionStorage.getItem("COACH_BEFORE_PATH"))//初始进入页面的地址
  },
  mutations: {
    // 更新token
    set_loginToken(state, value) {
      state.loginToken = value;
      if (value != "") {
        sessionStorage.setItem("COACH_LOGIN_TOKEN", JSON.stringify(value));
      } else {
        sessionStorage.removeItem("COACH_LOGIN_TOKEN");
      }
    },
    // 更新登录id
    set_loginUserId(state, value) {
      state.loginUserId = value;
      if (value != "") {
        sessionStorage.setItem("COACH_LOGIN_USERID", JSON.stringify(value));
      } else {
        sessionStorage.removeItem("COACH_LOGIN_USERID");
      }
    },
    // 更新登录用户是否绑定手机
    set_hasPhone(state, value) {
      if (value == 1) {
        state.set_hasPhone = false;
        sessionStorage.setItem("COACH_HAS_PHONE", JSON.stringify(false));
      } else {
        state.set_hasPhone = true;
        sessionStorage.setItem("COACH_HAS_PHONE", JSON.stringify(true));
      }
    },
    // 更新登录用户是否完善信息
    set_isRegister(state, value) {
      if (value == 1) {
        state.isRegister = false;
        sessionStorage.setItem("COACH_IS_REGISTER", JSON.stringify(false));
      } else {
        state.isRegister = true;
        sessionStorage.setItem("COACH_IS_REGISTER", JSON.stringify(true));
      }
    },
    // 更新登录用户是否存在已支付注册订单
    set_isRefereePay(state, value) {
      if (value == 0) {
        state.isRefereePay = false;
        sessionStorage.setItem("COACH_IS_REFEREEPAY", JSON.stringify(false));
      } else {
        state.isRefereePay = true;
        sessionStorage.setItem("COACH_IS_REFEREEPAY", JSON.stringify(true));
      }
    },
    // 更新登录用户是否存在已支付注册订单
    set_isAnswer(state, value) {
      if (value == 0) {
        state.isAnswer = false;
        sessionStorage.setItem("COACH_IS_ANSWER", JSON.stringify(false));
      } else {
        state.isAnswer = true;
        sessionStorage.setItem("COACH_IS_ANSWER", JSON.stringify(true));
      }
    },
    set_beforePath(state, value) {
      if (value) {
        state.before_Path = value
        console.log(state.before_Path);
        sessionStorage.setItem("COACH_BEFORE_PATH", JSON.stringify(value));
      }
    }
  },
  actions: {},
  modules: {},
});
